package com.spring.shops.service.impl;

import com.spring.shops.dao.TzProdPropMapper;
import com.spring.shops.dao.TzProdPropValueMapper;
import com.spring.shops.model.entity.TzProdProp;
import com.spring.shops.model.entity.TzProdPropValue;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.ProdPropVO3;
import com.spring.shops.service.ProdPropService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

@Service
public class ProdPropServiceImpl2 implements ProdPropService2 {
    @Autowired
    private TzProdPropMapper mapper;
    @Autowired
    private TzProdPropValueMapper valueMapper;
    /**
     * 列出产品的所有属性
     * @return
     */
    @Override
    public ServerResponseEntityVoid<List<ProdPropVO3>> listSpec() {
        List<TzProdProp> list=mapper.listSpac();
        List<ProdPropVO3> res=new ArrayList<>();
        //属性赋值
        for (TzProdProp prop : list) {
            Byte rule = prop.getRule();
            Integer rule2= Integer.valueOf(rule);
            res.add(new ProdPropVO3(
                    prop.getPropId(), prop.getPropName(),rule2, prop.getShopId(), null
            ));
        }
        return ServerResponseEntityVoid.success(res);
    }
    /**
     * 根据产品属性id获取产品属性的所有值
     * @param specId
     */
    @Override
    public ServerResponseEntityVoid<List<TzProdPropValue>> getSpecValuesById(Integer specId) {
        List<TzProdPropValue> res=valueMapper.getSpecValuesByPropId(specId);
        return ServerResponseEntityVoid.success(res);
    }
    /**
     * 根据产品属性所有值的最大值id
     * @param
     */
    @Override
    public ServerResponseEntityVoid<Long> listSpecMaxValueId() {
        Long maxValueId=valueMapper.maxValueId();
        return ServerResponseEntityVoid.success(maxValueId);
    }
}
